﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
using SubSonic;

public partial class DelayCalculator : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void ButtonCalculate_Click(object sender, EventArgs e)
    {
        TblTaskCollection taskCollection = new TblTaskCollection();
        taskCollection.LoadAndCloseReader(TblTask.FetchAll());
        foreach (var task in taskCollection)
        {
            if (task.IsDonei == true)
            {
                Query query = new Query(TblTask.Schema);
                query.AddWhere(TblTask.Columns.Id, task.Id);
                query.AddUpdateSetting(TblTask.Columns.DelayDays,
                                       Business.DelayCalculations.Delay(task.Id, Convert.ToDateTime(task.DateX)));
                query.QueryType = QueryType.Update;
                query.BuildUpdateCommand();
                query.Execute();
            }
        }
    }
}